From bb8f13140511ed29ec34241c6119525e21b95f09 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:09:48 -0700 Subject: [PATCH] convert mapfactor to Format class (#843) * convert mapfactor to Format class. * const memb funcs. --- CMakeLists.txt | 1 + GPSBabel.pro | 1 + mapfactor.cc | 83 +++++++++++++++++------------------------------ mapfactor.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ vecs.h | 4 +-- 5 files changed, 121 insertions(+), 56 deletions(-) create mode 100644 mapfactor.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cb48a65fe..616d385e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,6 +249,7 @@ set(HEADERS legacyformat.h lowranceusr.h magellan.h + mapfactor.h mynav.h navilink.h nmea.h diff --git a/GPSBabel.pro b/GPSBabel.pro index 9957d9f4f..6a1ada81e 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -236,6 +236,7 @@ HEADERS = \ legacyformat.h \ lowranceusr.h \ magellan.h \ + mapfactor.h \ mynav.h \ navilink.h \ nmea.h \ diff --git a/mapfactor.cc b/mapfactor.cc index 6aaf06226..28710d0c2 100644 --- a/mapfactor.cc +++ b/mapfactor.cc @@ -16,30 +16,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "defs.h" -#include "src/core/file.h" -#include "src/core/xmlstreamwriter.h" -#include -#include -#include +#include "mapfactor.h" -static gpsbabel::File* oqfile; -static QXmlStreamWriter* writer; +#include // for QByteArray +#include // for QIODevice, operator|, QIODevice::ReadOnly, QIODevice::Text, QIODevice::WriteOnly +#include // for qPrintable +#include // for QStringLiteral +#include // for QXmlStreamAttributes +#include // for QXmlStreamReader, QXmlStreamReader::EndElement, QXmlStreamReader::StartElement +#include // for QXmlStreamWriter -static -QVector mapfactor_args = { -}; +#include "defs.h" // for Waypoint, fatal, waypt_add, waypt_disp_all +#include "src/core/file.h" // for File +#include "src/core/xmlstreamwriter.h" // for XmlStreamWriter -#define MYNAME "mapfactor" - -// This really should be class-local... -static QXmlStreamReader reader; -static QString mapfactor_read_fname; -static const double milliarcseconds = 60.0 * 60.0 * 1000.0; -geocache_container wpt_container(const QString&); +#define MYNAME "mapfactor" -static void MapfactorRead() +void MapfactorFormat::MapfactorRead() { Waypoint* wpt = nullptr; @@ -66,14 +60,14 @@ static void MapfactorRead() } } -static void -mapfactor_rd_init(const QString& fname) +void +MapfactorFormat::rd_init(const QString& fname) { mapfactor_read_fname = fname; } -static void -mapfactor_read() +void +MapfactorFormat::read() { gpsbabel::File file(mapfactor_read_fname); file.open(QIODevice::ReadOnly); @@ -89,14 +83,8 @@ mapfactor_read() } } - -static void -mapfactor_rd_deinit() -{ -} - -static void -mapfactor_wr_init(const QString& fname) +void +MapfactorFormat::wr_init(const QString& fname) { oqfile = new gpsbabel::File(fname); oqfile->open(QIODevice::WriteOnly | QIODevice::Text); @@ -107,8 +95,8 @@ mapfactor_wr_init(const QString& fname) writer->writeStartDocument(); } -static void -mapfactor_wr_deinit() +void +MapfactorFormat::wr_deinit() { writer->writeEndDocument(); delete writer; @@ -118,8 +106,8 @@ mapfactor_wr_deinit() oqfile = nullptr; } -static void -mapfactor_waypt_pr(const Waypoint* waypointp) +void +MapfactorFormat::mapfactor_waypt_pr(const Waypoint* waypointp) const { writer->writeStartElement(QStringLiteral("item")); @@ -129,30 +117,17 @@ mapfactor_waypt_pr(const Waypoint* waypointp) writer->writeEndElement(); } -static void -mapfactor_write() +void +MapfactorFormat::write() { writer->writeStartElement(QStringLiteral("favourites")); writer->writeAttribute(QStringLiteral("version"), QStringLiteral("1")); // TODO: This could be moved to wr_init, but the pre GPX version put the two // lines above this, so mimic that behaviour exactly. writer->setAutoFormatting(true); - waypt_disp_all(mapfactor_waypt_pr); + auto mapfactor_waypt_pr_lambda = [this](const Waypoint* waypointp)->void { + mapfactor_waypt_pr(waypointp); + }; + waypt_disp_all(mapfactor_waypt_pr_lambda); writer->writeEndElement(); } - -ff_vecs_t mapfactor_vecs = { - ff_type_file, - { (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none, ff_cap_none }, - mapfactor_rd_init, - mapfactor_wr_init, - mapfactor_rd_deinit, - mapfactor_wr_deinit, - mapfactor_read, - mapfactor_write, - nullptr, - &mapfactor_args, - CET_CHARSET_UTF8, 0 /* CET-REVIEW */ - , NULL_POS_OPS, - nullptr -}; diff --git a/mapfactor.h b/mapfactor.h new file mode 100644 index 000000000..fad7f23df --- /dev/null +++ b/mapfactor.h @@ -0,0 +1,88 @@ +/* + Copyright (C) 2014 Robert Lipe + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +#ifndef MAPFACTOR_H_INCLUDED_ +#define MAPFACTOR_H_INCLUDED_ + +#include // for QString +#include // for QVector +#include // for QXmlStreamReader +#include // for QXmlStreamWriter + +#include "defs.h" // for ff_cap, arglist_t, ff_cap_none, CET_CHARSET_UTF8, Waypoint, ff_cap_read, ff_cap_write, ff_type, ff_type_file +#include "format.h" // for Format +#include "src/core/file.h" // for File + + +class MapfactorFormat : public Format +{ +public: + QVector* get_args() override + { + return &mapfactor_args; + } + + ff_type get_type() const override + { + return ff_type_file; + } + + QVector get_cap() const override + { + /* waypoints, tracks, routes */ + return { (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none, ff_cap_none }; + } + + QString get_encode() const override + { + return CET_CHARSET_UTF8; + } + + int get_fixed_encode() const override + { + return 0; + } + + void rd_init(const QString& fname) override; + void read() override; + void wr_init(const QString& fname) override; + void write() override; + void wr_deinit() override; + +private: + /* Constants */ + + static constexpr double milliarcseconds = 60.0 * 60.0 * 1000.0; + + /* Member Functions */ + + void MapfactorRead(); + void mapfactor_waypt_pr(const Waypoint* waypointp) const; + + /* Data Members */ + + gpsbabel::File* oqfile{}; + QXmlStreamWriter* writer{}; + + QVector mapfactor_args = { + }; + + QXmlStreamReader reader; + QString mapfactor_read_fname; +}; +#endif // MAPFACTOR_H_INCLUDED_ diff --git a/vecs.h b/vecs.h index 6afa0e04c..e82dc6b7f 100644 --- a/vecs.h +++ b/vecs.h @@ -42,6 +42,7 @@ #include "kml.h" #include "legacyformat.h" #include "lowranceusr.h" +#include "mapfactor.h" #include "mynav.h" #include "nmea.h" #include "osm.h" @@ -126,7 +127,6 @@ extern ff_vecs_t enigma_vecs; extern ff_vecs_t format_garmin_xt_vecs; extern ff_vecs_t mapbar_track_vecs; extern ff_vecs_t f90g_track_vecs; -extern ff_vecs_t mapfactor_vecs; #endif // MAXIMAL_ENABLED class Vecs @@ -321,7 +321,7 @@ private: GarminFitFormat format_fit_fmt; LegacyFormat mapbar_track_fmt {mapbar_track_vecs}; LegacyFormat f90g_track_fmt {f90g_track_vecs}; - LegacyFormat mapfactor_fmt {mapfactor_vecs}; + MapfactorFormat mapfactor_fmt; EnergymproFormat energympro_fmt; MyNavFormat mynav_fmt; GeoJsonFormat geojson_fmt; -- 2.30.2